<%--
  Created by IntelliJ IDEA.
  User: 86181
  Date: 2022/11/16
  Time: 11:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>出库调度单</title>
</head>
<body>
        <div>
            <button class="btn btn-primary" onclick="outpaydispathdangss()">退出</button>
            <button onclick="updatepaydispatch()" class="btn btn-primary">提交</button>
            <input type="hidden" id="paudispatchdangid">
        </div>
        <div style="width:1000px;height:700px;border:1px black dashed">
                    <div class="row">
                        <div class="col-md-offset-4"><h2><strong>出库调度单</strong></h2></div>
                    </div>
                    <br>
                    <div>
                        <div class="col-md-6">
                            <table>
                                <tr>
                                    <td>出库单编号:</td>
                                    <td><input type="text" id="paydispatchdangpayId" readonly style="outline: none;border: none"></td>
                                </tr>
                                <tr>
                                    <td>出库理由:</td>
                                    <td><input type="text" id="paydispatchdangreason" readonly style="outline: none;border: none"></td>
                                </tr>
                            </table>
                        </div>
                        <div class="col-md-6">
                            <table>
                                <tr>
                                    <td>出库详情理由:</td>
                                    <td><input type="text" id="paydispatchdangreasonexact" readonly style="outline: none;border: none"></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <br>
                    <div style="height:65%">
                        <div class="col-md-offset-10"><button class="btn btn-default" onclick="jiazaigatherson()"><span class="glyphicon glyphicon-refresh"></span></button></div>
                        <table id="paydispatchdangtab">

                        </table>
                    </div>
                    <br>
                    <div class="row">
                        <div class="col-md-6">
                            <table>
                                <tr>
                                    <td>应出库数量:</td>
                                    <td><input id="paydispatchdangamountSum" type="text" style="outline: none;border: none"></td>
                                </tr>
                            </table>
                        </div>
                        <div class="col-md-6">
                            <table>
                                <tr>
                                    <td>已出库数量:</td>
                                    <td><input id="paydispatchdangpaidAmountSum" type="text" style="outline: none;border: none"></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
                <!--调度模态框-->
                <div class="modal fade"  tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel" id="paydisptchdangdumodal" >
                    <div class="modal-dialog modal-lg">
                        <div class="modal-content" id="paydisptchdangdumodalson">
                        </div>
                    </div>
                </div>
        <script>
            //加载数据
            $(function () {
                //加载表格数据
                $("#paydispatchdangtab").bootstrapTable({
                    sidePagination:"server", //分页方式：client客户端分页，server服务端分页（*）
                    minimumCountColumns: 2,//最少允许的列数
                    columns:[
                        {
                            field:"",
                            title:"序号",
                            formatter:function (value,row,index) {
                                return Number(index)+1
                            }
                        },
                        {
                            field:"productName",
                            title:"产品名称",
                        },
                        {
                            field:"productId",
                            title:"产品编号",
                        },
                        {
                            field:"amount",
                            title:"应出库件数",
                        },
                        {
                            field:"paidAmount",
                            title:"已出库件数",
                        },
                        {
                            field:"",
                            title:"调度",
                            formatter:function (value,row,index) {
                                console.log(row)
                                if(row.payTag!="K002-2"){
                                    return "<input type='button' onclick='paydipatchdangdubtn("+row.productId+")'  value='调度' class='btn btn-primary'>"
                                }else {
                                    return "<input type='button' onclick='paydipatchdangdubtn("+row.productId+")' disabled value='完成' class='wcinput'>"
                                }
                            }
                        }
                    ]
                })
                jiazaigatherson();
            })
            function jiazaigatherson() {
                //获取值
                var payId='${param.payId}'
                //查询数据
                $.post("queryByPayPayIdson.action",{"payId":payId},function (data) {
                    //赋值
                    //出库编号
                    $("#paydispatchdangpayId").val(data.payId)
                    //出库理由
                    var reasons="";
                    if(data.reason=="C002-1"){
                        reasons="生产领料"
                    }
                    if(data.reason=="C002-2"){
                        reasons="赠送"
                    }
                    if(data.reason=="C002-3"){
                        reasons="内部借领"
                    }
                    if(data.reason==" C002-4"){
                        reasons="其他借领"
                    }
                    $("#paydispatchdangreason").val(reasons)
                    //出库详情理由
                    $("#paydispatchdangreasonexact").val(data.reasonexact)
                    //应出库数量
                    $("#paydispatchdangamountSum").val(data.amountSum)
                    //已出库数控
                    $("#paydispatchdangpaidAmountSum").val(data.paidAmountSum)
                    //id
                    $("#paudispatchdangid").val(data.id)
                    //天机表格数据
                    var arr=[]
                    var arrs=data.payDetails;
                    if(arrs==null || arrs==""){
                        return
                    }
                    for(var i=0;i<arrs.length;i++){
                        arr.push(arrs[i])
                    }
                    $("#paydispatchdangtab").bootstrapTable("load",arr)

                },"json")
            }
            //入库调度
            function paydipatchdangdubtn(productId) {
                //获取当前出库的id
                var id=$("#paudispatchdangid").val();
                //打开模态框
                $("#paydisptchdangdumodalson").load("paydispatchdangmodal.jsp",{"productId":productId,"id":id})
                $("#paydisptchdangdumodal").modal("show")

            }
            //退出
            function outpaydispathdangss() {
                $("#tab1").addTabs("制定出库单", "", "paydispatch.jsp", true);
                $("#tab1").closeTabs("出库调度单")
                $("#paydispatchtab").bootstrapTable("refresh")
            }
            //提交
            function updatepaydispatch() {
                var is=0;
                var arrs=$("#paydispatchdangtab").bootstrapTable("getData")
                if($(".wcinput").length!=arrs.length){
                    alert("请调度产品后在确定")
                    is++
                }
                 if(is==0){
                      //获取出库编号
                      $.post("updatePayByPayId.action",{"payId":$("#paydispatchdangpayId").val()},function (data) {
                          alert(data.msg)
                          //刷新表格
                          $("#tab1").addTabs("制定出库单", "", "paydispatch.jsp", true);
                          $("#tab1").closeTabs("出库调度单")
                      },"json")
                  }

            }
        </script>
</body>
</html>
